﻿Imports System.Data
Imports System.Data.SqlClient

Public Class CombustiveisVeiculosDAL
    Public Sub incluir(vei_codigo As Integer, com_codigo As Integer)
        Try
            Dim cmd As New SqlCommand
            Dim objD As New Dados
            cmd.CommandText = "insert into combustiveisveiculo(vei_codigo, com_codigo) values (@vei_codigo, @com_codigo)"
            cmd.Parameters.Add(New SqlParameter("@vei_codigo", SqlDbType.Int)).Value = vei_codigo
            cmd.Parameters.Add(New SqlParameter("@com_codigo", SqlDbType.Int)).Value = com_codigo
            objD.executacomando(cmd)
            cmd = Nothing
            objD = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    'excluir todos os produtos do consumo
    Public Sub excluirTodos(ByVal vei_codigo As Integer)
        Try
            Dim cmd As New SqlCommand
            Dim objD As New Dados
            cmd.CommandText = "delete from combustiveisveiculo where vei_codigo = @vei_codigo"
            cmd.Parameters.Add(New SqlParameter("@vei_codigo", SqlDbType.Int)).Value = vei_codigo
            objD.executacomando(cmd)
            cmd = Nothing
            objD = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub



    Public Function buscarCombustivel(ByVal codCombustivel As Integer) As DataTable
        Dim cmd As New SqlCommand
        Dim objD As New Dados
        Dim tab As DataTable
        Try
            cmd.CommandText = "select * from combustivel where com_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codCombustivel
            tab = objD.executaConsulta(cmd)
        Catch ex As Exception
            Throw ex
        End Try
        cmd = Nothing
        objD = Nothing
        Return tab

    End Function

    Public Function localizarTodos(ByVal vei_codigo As Integer) As DataTable
        Dim tab As New DataTable
        Try
            Dim cmd As New SqlCommand
            Dim objD As New Dados
            cmd.CommandText = "select * from combustiveisveiculo where vei_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = vei_codigo
            tab = objD.executaConsulta(cmd)
            objD = Nothing
            cmd = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return tab
    End Function

    Public Function localizar(ByVal vei_codigo As Integer) As DataTable
        Dim tab As New DataTable
        Try
            Dim cmd As New SqlCommand
            Dim objD As New Dados
            cmd.CommandText = "select * from combustiveisveiculo where vei_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = vei_codigo
            tab = objD.executaConsulta(cmd)
            objD = Nothing
            cmd = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return tab
    End Function

    Public Function localizar(ByVal vei_codigo As Integer, ByVal com_codigo As Integer) As DataTable
        Dim tab As New DataTable
        Try
            Dim cmd As New SqlCommand
            Dim objD As New Dados
            cmd.CommandText = "select * from combustiveisveiculo where vei_codigo = @vei_codigo and com_codigo = @com_codigo"
            cmd.Parameters.Add(New SqlParameter("@vei_codigo", SqlDbType.Int)).Value = vei_codigo
            cmd.Parameters.Add(New SqlParameter("@com_codigo", SqlDbType.Int)).Value = com_codigo
            tab = objD.executaConsulta(cmd)
            objD = Nothing
            cmd = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return tab
    End Function

    Public Sub alterar(vei_codigo As Integer, com_codigo As Integer)
        Dim cmd As New SqlCommand
        Dim objD As New Dados

        Try
            cmd.CommandText = "update combustiveisveiculo set com_codigo=@produto where vei_codigo = @vei_codigo"
            cmd.Parameters.Add(New SqlParameter("@com_codigo", SqlDbType.Int)).Value = com_codigo
            cmd.Parameters.Add(New SqlParameter("@vei_codigo", SqlDbType.Int)).Value = vei_codigo
            objD.executacomando(cmd)
        Catch ex As Exception
            Throw ex
        End Try
        cmd = Nothing
        objD = Nothing
    End Sub
End Class
